/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.ComputerPlayer;
import Model.Die;
import Model.HumanPlayer;
import Model.Player;
import Model.Token;
import View.DicePanelWithButton;
import View.BoardCreator;
import View.CustomBoard;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Tom Gurung
 */
public class CustomBoardController {
    private CustomBoard customView;
    private ArrayList<Integer> uppersVal = new ArrayList(10);
    private ArrayList<Integer> downersVal = new ArrayList(10);
    String playerName;
    
    public CustomBoardController(CustomBoard view, String name) {
        playerName = name;
        customView = view;
        customView.addActionListener(new CustomBoardListener());
        
    }
    
    public class CustomBoardListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("Save Ups")) {
            uppersVal = customView.getUppers();
            JOptionPane.showMessageDialog(null, "Saved!");

        }
        else if(e.getActionCommand().equals("Save Downs")) {
            
            downersVal = customView.getDowns();
            JOptionPane.showMessageDialog(null, "Saved!");
            
        }
        else if(e.getActionCommand().equals("Create")) {
            
            int rows = customView.getRows();
            int cols = customView.getColums();
            
            ArrayList<Integer> tokUps = uppersVal;
            ArrayList<Integer> tokDowns = downersVal;
            
            Die aDie = new Die();
            Player cmpPlayer = new ComputerPlayer();
            Player humPlayer = new HumanPlayer(playerName);
            
            Token cmpToken = new Token(rows*cols, tokUps, tokDowns, cmpPlayer, 1);
            Token humToken = new Token(rows*cols, tokUps, tokDowns, humPlayer, 1);
           
            BoardCreator newBoard = new BoardCreator(rows, cols, uppersVal, downersVal, playerName);
            BoardCreatorController boardControl = new BoardCreatorController(newBoard, aDie, cmpPlayer, humPlayer, cmpToken, humToken);
            
            customView.dispose();//close the custom board creating JFrame
 
        }
    
    
    
        
    }//End action Performed
    }//End custom board listener
}//End class
